﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Security.Cryptography;
using System.Text;

namespace TARS.User
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

      
        protected void btnLogin_Click(object sender, EventArgs e)
        {

            using (var db = new TARSDelivery_EprojectEntities())
            {
                
                string pass = Encryption.GetMd5Hash(txtPass.Text);
                var login = db.t_User.Where(x => x.Username == txtUser.Text && x.Password == pass);
                if (login.Count() < 1)
                {
                    Label3.Visible = true;
                    Label3.Text = "User or Password incorrect";
                }
                else
                {                   
                    foreach (var lg in login)
                    {
                        Session["BranchesZoneID"] = "";
                        Session["IDUser"] = lg.ID;
                        Session["BranchesID"] = lg.BranchesID;
                        Session["UserType"] = lg.UserType;
                        var emp = db.t_EmployeeInfo.Where(x => x.UserID == lg.ID);
                        foreach(var empID in emp)
                        {
                            
                            Session["IDemployee"] = empID.ID;
                        }
                    }
                    Response.Redirect("DeliveryMaster.aspx");
                }
            }
        }
    }
}